1 /** 2 * License: 3 * Copyright Devisualization (Richard Andrew Cattermole) 2014 - 2017. 4 * Distributed under the Boost Software License, Version 1.0. 5 * (See accompanying file LICENSE_1_0.txt or copy at 6 * http://www.boost.org/LICENSE_1_0.txt) 7 */ 8 module devisualization.util.core.time; 9 import std.datetime : SysTime, Clock; 10 import core.time : Duration; 11 12 /** 13 * UTC+0 time 14 */ 15 @property { 16 /** 17 * Gets the current time without any offsets. 18 * 19 * Returns: 20 * The time (UNIX) without any offsets. 21 */ 22 ulong utc0Time() { 23 return utc0SysTime().toUnixTime(); 24 } 25 26 /** 27 * Gets the current time without any offsets. 28 * 29 * Returns: 30 * The time without any offsets. 31 */ 32 SysTime utc0SysTime() { 33 return Clock.currTime().removeOffset; 34 } 35 36 /** 37 * Gets the time this application was compiled without any offsets. 38 * 39 * Returns: 40 * The time (UNIX) without any offsets. 41 */ 42 ulong utc0Compiled() { 43 return utc0CompiledSysTime().toUnixTime(); 44 } 45 46 /** 47 * Gets the time this application was compiled without any offsets. 48 * 49 * Returns: 50 * The time without any offsets. 51 */ 52 SysTime utc0CompiledSysTime() { 53 import devisualization.util.core.text : replace, split; 54 string timestamp = __TIMESTAMP__.replace(" ", " "); 55 string[] values = timestamp.split(" "); 56 57 string timeo; 58 timeo ~= values[4] ~ "-"; 59 timeo ~= values[1] ~ "-"; 60 61 if (values[2].length == 1) 62 timeo ~= "0"; 63 timeo ~= values[2] ~ " "; 64 65 timeo ~= values[3]; 66 67 return SysTime.fromSimpleString(timeo).removeOffset; 68 } 69 } 70 71 /** 72 * Removes the offset on a time object 73 */ 74 SysTime removeOffset(SysTime time) { 75 time -= time.utcOffset; 76 return time; 77 } 78 79 private { 80 string utc0CompiledTimeStamp() { 81 import devisualization.util.core.text : split; 82 import std.conv : to; 83 import std..string : toUpper; 84 auto time = utc0CompiledSysTime(); 85 86 string dayOfWeek = to!string(time.dayOfWeek); 87 string month = to!string(time.month); 88 dayOfWeek = cast(char)toUpper(dayOfWeek[0]) ~ dayOfWeek[1 .. $]; 89 month = cast(char)toUpper(month[0]) ~ month[1 .. $]; 90 91 string output; 92 output ~= dayOfWeek ~ ", "; 93 output ~= to!string(time.day) ~ " "; 94 output ~= month ~ " "; 95 output ~= to!string(time.year) ~ " "; 96 output ~= time.toSimpleString().split(" ")[1] ~ " GMT"; 97 98 return output; 99 } 100 }